<?php

namespace App\Console\Commands;

use App\Models\WheatPrice;
use Illuminate\Console\Command;

class AutoAddWheatPrice extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:autoaddwheatprice';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description:自动添加小麦价格';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $first = WheatPrice::orderBy('now_date','desc')->first();
        WheatPrice::updateOrCreate(
            ['now_date'=>date("Y-m-d")],
            ['now_date'=>date("Y-m-d"),'p_price'=>$first->p_price,'s_price'=>$first->s_price]
        );
    }
}
